package com.yiwei.zhh.api.requestInfo;

import com.yiwei.zhh.api.Api;
import com.yiwei.zhh.api.bean.MessageDetailBean;
import com.yiwei.zhh.api.callback.HelpDetailContract;
import com.yiwei.zhh.util.Network;
import com.yiwei.zhh.util.RxLifeUtil;
import com.yiwei.zhh.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class HelpDetailRequest extends BaseRequest<HelpDetailContract.View> implements HelpDetailContract.Presenter<HelpDetailContract.View> {

    public static HelpDetailRequest create() {
        return new HelpDetailRequest();
    }

    @Override
    public void getHelpDetailInfo(String id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();

        Api.api_service.getHelpDetailInfo(id).compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    if (result.getStatus() != 0) {
                        mView.getHelpDetailInfoSuccess(result);
                    } else {
                        mView.getHelpDetailInfoFail(result.getMsg());
                    }

                });
    }

    @Override
    public void getMessageDetailInfo(String id) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        MessageDetailBean bean = new MessageDetailBean();
        bean.id = id;
        Api.api_service.getMessageDetailInfo(bean).compose(RxLifeUtil.NocheckOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    if (result.getStatus() != 0) {
                        mView.getMessageDetailInfoSuccess(result);
                    } else {
                        mView.getMessageDetailInfoFail(result.getMsg());
                    }

                });
    }
}
